package com.android.semita;

import android.os.Bundle;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

public class FeedBackActivity extends Activity {

	public TextView tv1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_feed_back);

		tv1 = (TextView) findViewById(R.id.showScore);

		// seekBar1
		final RatingBar rating_Bar = (RatingBar) findViewById(R.id.ratingBar1);
		rating_Bar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

					@Override
					public void onRatingChanged(RatingBar ratingBar,
							float rating, boolean fromUser) {
						tv1.setText("Rate score : " + String.valueOf(rating));

					}
				});

		// button1
		final Button saveBtn = (Button) findViewById(R.id.saveBtn);
		saveBtn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Toast.makeText(
						FeedBackActivity.this,
						String.valueOf("Your Selected : "
								+ rating_Bar.getRating()), Toast.LENGTH_SHORT)
						.show();
			}
		});

		// ***********demo pop up rating*********
		final Button btn1 = (Button) findViewById(R.id.demoBtn);
		btn1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				ShowDialog();

			}
		});
	}

	public void ShowDialog() {
		final AlertDialog.Builder popDialog = new AlertDialog.Builder(this);
		final RatingBar rating = new RatingBar(this);
		rating.setMax(5);
		rating.setNumStars(5);
		rating.setStepSize(0.5f);
		rating.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT));
		LinearLayout parent = new LinearLayout(FeedBackActivity.this);
		parent.setGravity(Gravity.CENTER);
		parent.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT));
		parent.addView(rating);

		popDialog.setIcon(android.R.drawable.btn_star_big_on);
		popDialog.setTitle("Rate!! ");
		popDialog.setView(parent);

		// Button OK
		popDialog.setPositiveButton(android.R.string.ok,
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						double score = Double.parseDouble(String.valueOf(rating.getProgress()));
						score = score /2 ;
						tv1.setText("Your Selected (from pop up) : "
								+ score);
						dialog.dismiss();
					}
				})

		// Button Cancel
				.setNegativeButton("Cancel",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								dialog.cancel();
							}
						});

		popDialog.create();
		popDialog.show();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.feed_back, menu);
		return true;
	}

}
